using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientGroupController : Controller
    {
		private readonly IPatientGroupRepository patientgroupRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientGroupController()// : this(new PatientGroupRepository())
        {
            patientgroupRepository = Registry.RepositoryFactory.GetPatientGroupRepository();
        }

        public PatientGroupController(IPatientGroupRepository patientgroupRepository)
        {
			this.patientgroupRepository = patientgroupRepository;
        }

        //
        // GET: /PatientGroup/

        public ViewResult Index()
        {
            return View(patientgroupRepository.All);//Including(patientgroup => patientgroup.Parents, patientgroup => patientgroup.Children, patientgroup => patientgroup.Patients));
        }

        //
        // GET: /PatientGroup/Details/5

        public ViewResult Details(int id)
        {
            return View(patientgroupRepository.Find(id));
        }

        //
        // GET: /PatientGroup/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /PatientGroup/Create

        [HttpPost]
        public ActionResult Create(PatientGroup patientgroup)
        {
            if (ModelState.IsValid) {
                patientgroupRepository.Create(patientgroup);
                patientgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /PatientGroup/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(patientgroupRepository.Find(id));
        }

        //
        // POST: /PatientGroup/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientGroup patientgroup)
        {
            if (ModelState.IsValid) {
                patientgroupRepository.Update(patientgroup);
                patientgroupRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /PatientGroup/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(patientgroupRepository.Find(id));
        }

        //
        // POST: /PatientGroup/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            var pg = patientgroupRepository.Find(id);
            patientgroupRepository.Delete(pg);
            patientgroupRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

